找传奇、传世资源到传世资源站!

CSharp Pcap例子WakeOnLan

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

CSharp Pcap的网络唤醒
var devices = CaptureDeviceList.Instance;

            // if no devices were found print an error
            if(devices.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine("The following devices are available on this machine:");
            Console.WriteLine("----------------------------------------------------");
            Console.WriteLine();

            int i = 0;

            // scan the list printing every entry
            foreach(var dev in devices)
            {
                Console.WriteLine("{0}) {1} {2}",i,dev.Name,dev.Description);
                i ;
            }

            Console.WriteLine();
            Console.Write("-- Please choose a device to capture: ");
            i = int.Parse(Console.ReadLine());

            var device1 = devices[i];
            var device2 = CaptureDeviceList.New()[i];

            // register our handler function to the 'packet arrival' event
            device1.OnPacketArrival =
                new PacketArrivalEventHandler(device_OnPacketArrival);
            device2.OnPacketArrival =
                new PacketArrivalEventHandler(device_OnPacketArrival);

            // open the device for capturing
            int readTimeoutMilliseconds = 1000;
            device1.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);
            device2.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds);

            // tcpdump filter to capture only TCP/IP packets
            device1.Filter = "ether dst FF:FF:FF:FF:FF:FF and udp";
            device2.Filter = "ether dst FF:FF:FF:FF:FF:FF and ether proto 0x0842";

            Console.WriteLine();
            Console.WriteLine("-- Listening for packets... Hit 'Ctrl-C' to exit --");

            // start capture packets
            device1.Capture();
            device2.Capture();

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复